<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        // 简单匹配/abc/，只能匹配abc连着出现的情况
        var re = /abc/
        console.log(re.exec('aabc'))//exec匹配成功返回数组,失败返回null
        console.log(re.exec('abdc'))
        console.log(re.test('aabc'))//test匹配成功返回true,失败返回false
        console.log(re.test('abdc'))

        console.log('----------------------')
        // ^表示匹配的开头
        var re1 = /^a/
        console.log(re1.test('aa'))
        console.log(re1.test('ba'))

        console.log('----------------------')
        // $表示匹配的结尾
        var re2 = /abc$/
        console.log(re2.test('abc'))
        console.log(re2.test('abcd'))

        var re3 = /^ab*c$/
        console.log(re3.test('abbbbc'))
        console.log(re3.test('abbcbbc'))

        console.log('----------------------')
        // *表示上一个表达存在0个或多个
        var re4 = /ab*c/
        console.log(re4.test('cnabbbbbbbcd'))
        console.log(re4.test('ac'))
        
        console.log('----------------------')
        // +表示上一个表达存在1个或多个
        var re5 = /ab+c/
        console.log(re5.test('cnabbbbbbbcd'))
        console.log(re5.test('ac'))
        
        console.log('----------------------')
        // ?表示上一个表达存在0个或1个
        var re6 = /ab?c/
        console.log(re6.test('cnabbbbbbbcd'))
        console.log(re6.test('ac'))
        console.log(re6.test('abc'))
        
        console.log('----------------------')
        // .表示匹配任意表达式
        var re7 = /.c/
        console.log(re7.test('candy'))
        console.log(re7.test('f*ck'))

    </script>

</body>

</html>